/* ver: 0.1, date 19-12-2007 by Jeroen W
 * added and implemented necessary public methods: 
 * getElement, clear, isCleared, getSizeX, getSizeY.
 * ver: 0.2, date 02-01-2007 by Marcel Hekman
 * add clearSolveState
 * ver: 0.3, date 03-01-2007 by Marcel Hekman
 * bugfix: last item is cleared aswell now
 */

package mazeAssignment;


/**
 *
 * @author: jeroen, jeroen, marcel en teun
 */
public class SingleArrayMaze implements Maze{
    private int xSize, ySize;
    private boolean cleared;
    private MazeElement[] mazeGrid;

    //default constructor: 10 by 10 field.
    public SingleArrayMaze()
    {
        this(10, 10);
    }
    
    //dynamic constructor for the array
    public SingleArrayMaze(int x, int y)
    {
        mazeGrid = new MazeElement[x*y];
        cleared= true;
        xSize= x;
        ySize= y;
        for (int i=0; i<(mazeGrid.length); i++)
        {
        	mazeGrid[i] = new MazeElement();
            mazeGrid[i].clear();
        }
    }
    
    //returns requested MazeElement.
    public MazeElement getElement(int x, int y) {
        cleared = false;
        return mazeGrid[x*ySize + y];
    }
    
    //clears every object: makes every Wall true again;
    public void clear() {
        cleared = true;
        for(int i=0; i< mazeGrid.length; i++ )
        {
            mazeGrid[i].clear();
        }
    }
    
    public void clearSolveState()
    {
        for(int i=0; i< mazeGrid.length; i++ )
        {
            mazeGrid[i].clearSolveState();
        }
    }

    //returns true if cleared
    public boolean isCleared() {
        return cleared;
    }
    
    //returns x-size of maze
    public int getSizeX() {
        return xSize;
    }
    
    //returns y-size of maze
    public int getSizeY() {
       return ySize;
    }


}
